package top;


import java.util.Arrays;

/**
 * @author chenyw
 * @date 2022/7/13 10:56
 * @description
 */
public class Top179largestNumber {
    public String largestNumber(int[] nums) {
        int len = nums.length;
        StringBuffer sb = new StringBuffer();
        String[] str = new String[len];

        for (int i = 0; i < len; i++) {
            str[i] = String.valueOf(nums[i]);
        }

        Arrays.sort(str,(a, b) -> {
            return (b + a).compareTo(a + b);
        });
        if (str[0].equals("0")) {
            return "0";
        }

        for (int i = 0; i < len; i++) {
            sb.append(str[i]);
        }
        return sb.toString();
    }


    private void swap(int[] nums, int l, int r) {
        int tmp = nums[l];
        nums[l] = nums[r];
        nums[r] = tmp;
    }
}
